package com.qqtech.qquan.pub.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtech.admin.context.AdminPage;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.model.Result;
import com.qqtech.core.frame.service.BaseService;
import com.qqtech.qquan.pub.model.PubSysParam;
import com.qqtech.qquan.pub.model.PubSysParamQuery;
import com.qqtech.qquan.pub.model.PubSysParamVo;
import com.qqtech.qquan.pub.model.PubUpgrade;
import com.qqtech.qquan.pub.service.PubSysParamService;
import com.qqtech.qquan.pub.service.PubUpgradeService;
import com.qqtech.qquan.sys.controller.BaseAdminController;

@Controller
@RequestMapping(value = "/pub/sysParam")
public class PubSysParamController extends BaseAdminController {
	@Resource
	private PubSysParamService pubSysParamService;

	@Resource
	private PubUpgradeService pubUpgradeService;

	@Override
	protected BaseService<PubSysParam> getBaseService() {
		return pubSysParamService;
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list() {
		return "/pubSysParam/pubSysParam-list";
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public AdminPage list(PubSysParamQuery query, HttpServletRequest request, HttpServletResponse response) {
		AdminPage adminPage = new AdminPage();
		//String rows = (String) request.getParameter("rows"); // 每页条数
		query.setSize(Integer.MAX_VALUE);
		Pageable pageKit = new PageKit(query.getPage(),query.getSize(), new PageOrder(Direction.DESC, "id"));
		List<Integer> filterIds = new ArrayList<Integer>();
		filterIds.add(1001);
		query.setFilterIds(filterIds);
		Page<PubSysParamVo> page = pubSysParamService.queryPageList(query, pageKit);
		adminPage.setRows(page.getContent());
		adminPage.setTotal(Integer.valueOf(page.getTotalElements() + ""));
		return adminPage;
	}
	/**
	 * 创建成功
	 * 
	 * @param shareId
	 * @return
	 */
	@RequestMapping(value = "/create")
	@ResponseBody
	public Result create(PubUpgrade pubUpgrade) {
		Result ret = new Result();
		ret = pubUpgradeService.publishNewVersion(pubUpgrade);
		return ret;
	}
}
